package com.umeng.analytics.pro;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public final class ch {
    static class a implements Comparator {
        private a() {

        }

        public int compare(Object arg2, Object arg3) {
            int v0;
            if (arg2 == null && arg3 == null) {
                v0 = 0;
            } else if (arg2 == null) {
                v0 = -1;
            } else if (arg3 == null) {
                v0 = 1;
            } else if ((arg2 instanceof List)) {
                v0 = ch.a(((List) arg2), ((List) arg3));
            } else if ((arg2 instanceof Set)) {
                v0 = ch.a(((Set) arg2), ((Set) arg3));
            } else if ((arg2 instanceof Map)) {
                v0 = ch.a(((Map) arg2), ((Map) arg3));
            } else if ((arg2 instanceof byte[])) {
                v0 = ch.a(((byte[]) arg2), ((byte[]) arg3));
            } else {
                v0 = ch.a(((Comparable) arg2), ((Comparable) arg3));
            }

            return v0;
        }
    }

    private static final Comparator a = new a();

    private ch() {

    }

    public static void a(ByteBuffer arg6, StringBuilder arg7) {
        byte[] v4 = arg6.array();
        int v0 = arg6.arrayOffset();
        int v3 = v0 + arg6.position();
        int v1 = arg6.limit() + v0;
        v0 = v1 - v3 > 128 ? v3 + 128 : v1;
        int v2;
        for (v2 = v3; v2 < v0; ++v2) {
            if (v2 > v3) {
                arg7.append(" ");
            }

            arg7.append(ch.a(v4[v2]));
        }

        if (v1 != v0) {
            arg7.append("...");
        }
    }

    public static int a(byte arg1, byte arg2) {
        int v0;
        if (arg1 < arg2) {
            v0 = -1;
        } else if (arg2 < arg1) {
            v0 = 1;
        } else {
            v0 = 0;
        }

        return v0;
    }

    public static int a(double arg2, double arg4) {
        int v0;
        if (arg2 < arg4) {
            v0 = -1;
        } else if (arg4 < arg2) {
            v0 = 1;
        } else {
            v0 = 0;
        }

        return v0;
    }

    public static int a(int arg1, int arg2) {
        int v0;
        if (arg1 < arg2) {
            v0 = -1;
        } else if (arg2 < arg1) {
            v0 = 1;
        } else {
            v0 = 0;
        }

        return v0;
    }

    public static int a(long arg2, long arg4) {
        int v0;
        if (arg2 < arg4) {
            v0 = -1;
        } else if (arg4 < arg2) {
            v0 = 1;
        } else {
            v0 = 0;
        }

        return v0;
    }

    public static int a(Comparable arg1, Comparable arg2) {
        return arg1.compareTo(arg2);
    }

    public static int a(Object arg3, Object arg4) {
        int v0;
        if ((arg3 instanceof Comparable)) {
            v0 = ch.a(((Comparable) arg3), ((Comparable) arg4));
        } else if ((arg3 instanceof List)) {
            v0 = ch.a(((List) arg3), ((List) arg4));
        } else if ((arg3 instanceof Set)) {
            v0 = ch.a(((Set) arg3), ((Set) arg4));
        } else if ((arg3 instanceof Map)) {
            v0 = ch.a(((Map) arg3), ((Map) arg4));
        } else if ((arg3 instanceof byte[])) {
            v0 = ch.a(((byte[]) arg3), ((byte[]) arg4));
        } else {
            throw new IllegalArgumentException("Cannot compare objects of type " + arg3.getClass());
        }

        return v0;

    }

    public static int a(List arg5, List arg6) {
        int v1 = 0;
        int v0 = ch.a(arg5.size(), arg6.size());
        if (v0 != 0) {
            v1 = v0;
        } else {
            v0 = 0;
            while (v0 < arg5.size()) {
                int v2 = ch.a.compare(arg5.get(v0), arg6.get(v0));
                if (v2 != 0) {
                    v1 = v2;
                } else {
                    ++v0;
                    continue;
                }

                return v1;
            }
        }

        return v1;
    }

    public static int a(Set arg5, Set arg6) {
        int v0 = ch.a(arg5.size(), arg6.size());
        if (v0 == 0) {
            TreeSet v0_1 = new TreeSet(ch.a);
            ((SortedSet) v0_1).addAll(((Collection) arg5));
            TreeSet v1 = new TreeSet(ch.a);
            ((SortedSet) v1).addAll(((Collection) arg6));
            Iterator v2 = ((SortedSet) v0_1).iterator();
            Iterator v1_1 = ((SortedSet) v1).iterator();
            do {
                if ((v2.hasNext()) && (v1_1.hasNext())) {
                    v0 = ch.a.compare(v2.next(), v1_1.next());
                    if (v0 == 0) {
                        continue;
                    }

                    return v0;
                }

                return 0;
            }
            while (true);
        }
        return v0;
    }

    public static int a(Map arg7, Map arg8) {
        int v0 = ch.a(arg7.size(), arg8.size());
        if (v0 == 0) {
            TreeMap v0_1 = new TreeMap(ch.a);
            ((SortedMap) v0_1).putAll(arg7);
            Iterator v3 = ((SortedMap) v0_1).entrySet().iterator();
            v0_1 = new TreeMap(ch.a);
            ((SortedMap) v0_1).putAll(arg8);
            Iterator v4 = ((SortedMap) v0_1).entrySet().iterator();
            do {
                if ((v3.hasNext()) && (v4.hasNext())) {
                    Object v0_2 = v3.next();
                    Object v1 = v4.next();
                    int v2 = ch.a.compare(((Map.Entry) v0_2).getKey(), ((Map.Entry) v1).getKey());
                    if (v2 != 0) {
                        return v2;
                    } else {
                        v0 = ch.a.compare(((Map.Entry) v0_2).getValue(), ((Map.Entry) v1).getValue());
                        if (v0 == 0) {
                            continue;
                        }

                        return v0;
                    }
                }

                return 0;
            }
            while (true);
        }
        return v0;
    }

    public static int a(byte[] arg4, byte[] arg5) {
        int v1 = 0;
        int v0 = ch.a(arg4.length, arg5.length);
        if (v0 != 0) {
            v1 = v0;
        } else {
            v0 = 0;
            while (v0 < arg4.length) {
                int v2 = ch.a(arg4[v0], arg5[v0]);
                if (v2 != 0) {
                    v1 = v2;
                } else {
                    ++v0;
                    continue;
                }

                return v1;
            }
        }

        return v1;
    }

    public static int a(String arg1, String arg2) {
        return arg1.compareTo(arg2);
    }

    public static int a(ByteBuffer arg4, byte[] arg5, int arg6) {
        int v0 = arg4.remaining();
        System.arraycopy(arg4.array(), arg4.arrayOffset() + arg4.position(), arg5, arg6, v0);
        return v0;
    }

    public static int a(short arg1, short arg2) {
        int v0;
        if (arg1 < arg2) {
            v0 = -1;
        } else if (arg2 < arg1) {
            v0 = 1;
        } else {
            v0 = 0;
        }

        return v0;
    }

    public static int a(boolean arg2, boolean arg3) {
        return Boolean.valueOf(arg2).compareTo(Boolean.valueOf(arg3));
    }

    public static String a(byte arg2) {
        return Integer.toHexString((arg2 | 256) & 511).toUpperCase().substring(1);
    }

    public static byte[] a(ByteBuffer arg2) {
        byte[] v0;
        if (ch.b(arg2)) {
            v0 = arg2.array();
        } else {
            v0 = new byte[arg2.remaining()];
            ch.a(arg2, v0, 0);
        }

        return v0;
    }

    public static byte[] a(byte[] arg3) {
        byte[] v0;
        if (arg3 == null) {
            v0 = null;
        } else {
            v0 = new byte[arg3.length];
            System.arraycopy(arg3, 0, v0, 0, arg3.length);
        }

        return v0;
    }

    public static boolean b(ByteBuffer arg2) {
        boolean v0 = !arg2.hasArray() || arg2.position() != 0 || arg2.arrayOffset() != 0 || arg2.remaining() != arg2.capacity() ? false : true;
        return v0;
    }

    public static ByteBuffer c(ByteBuffer arg1) {
        if (arg1 == null) {
            arg1 = null;
        } else if (!ch.b(arg1)) {
            arg1 = ByteBuffer.wrap(ch.a(arg1));
        }

        return arg1;
    }

    public static ByteBuffer d(ByteBuffer arg6) {
        ByteBuffer v0;
        if (arg6 == null) {
            v0 = null;
        } else {
            v0 = ByteBuffer.wrap(new byte[arg6.remaining()]);
            if (arg6.hasArray()) {
                System.arraycopy(arg6.array(), arg6.arrayOffset() + arg6.position(), v0.array(), 0, arg6.remaining());
            } else {
                arg6.slice().get(v0.array());
            }
        }

        return v0;
    }
}

